/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package taglibs;

import daos.ItemDAO;
import java.util.ArrayList;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.TagSupport;
import models.Item;

/**
 *
 * @author trietto
 */
public class Recommend extends TagSupport {

    /**
     *
     */
    private static final long serialVersionUID = 1L;

    /*
     * (non-Javadoc)
     * @see javax.servlet.jsp.tagext.TagSupport#doStartTag()
     */
    public int doStartTag() {
        try {
            JspWriter writer = pageContext.getOut();
            ArrayList<Item> lstItems = new ArrayList<Item>();

            lstItems = ItemDAO.singleton().selectRecommend();
            writer.println("<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">");
            writer.println("<tr>");
            writer.println("<td align='center'><b>RECOMMENDED</b><br></td>");
            writer.println("</tr>");

            Item item = null;
            for (int i = 0; i < lstItems.size(); i++) {
                item = lstItems.get(i);
                writer.println("<tr>");
                writer.println("<td><a href='BookDetail.jsp?itemid="+item.getItemId()+"'>"
                        + item.getName());
                writer.println("</a></td>");
                writer.println("</tr>");

                writer.println("<tr>");
                writer.println("<td>");
                writer.println("Author: " + item.getAuthor());
                writer.println("</td>");
                writer.println("</tr>");

                
                writer.println("<tr>");
                writer.println("<td>");
                writer.println("<img alt='' src='"+item.getImageURL()+"' />");
                writer.println("</td>");
                writer.println("</tr>");

                writer.println("<tr>");
                writer.println("<td>Price: "+item.getPrice());
                writer.println("</td>");
                writer.println("</tr>");

                writer.println("<tr>");
                writer.println("<td><a href='ShoppingCartServlet?itemid="+item.getItemId()
                        +"'>Add to Cart</a>");
                writer.println("</td>");
                writer.println("</tr>");

                if(i==4) break;
            }
            writer.println("</table>");
        } catch (Exception e) {
        }
        return SKIP_BODY;
    }
}
